home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / pibasync.arc / TIMEREC.ASM < prev   
Encoding:
Assembly Source File  |  1986-10-31  |  3.3 KB  |  81 lines

  1. ;
  2. ;  Check if a character in input comm buffer
  3. ;
  4.          MOV   AX,[>Async_Buffer_Tail]
  5.          CMP   AX,[>Async_Buffer_Head]
  6.          JNE   Rec1
  7. ;
  8. ;  Buffer empty -- begin wait loop.
  9. ;
  10.          MOV   AX,[BP+<Secs]                 ;Get seconds to wait
  11.          MOV   CX,10                         ;Shift count = 2 ** 10 = 1024
  12.          SHL   AX,CL                         ;Seconds * 1024 = milleseconds
  13.          MOV   CX,AX                         ;Move to looping register
  14. ;
  15. ;  Delay for 1 ms.
  16. ;
  17. Delay:   PUSH  CX                            ;Save milleseconds to go
  18.          MOV   CX,[$12]                      ;Get Turbo's delay loop value for 1 ms
  19. Delay1:  LOOP  Delay1                        ;Tight loop for 1 ms delay
  20. ;
  21. ;  Check if any character yet.
  22. ;
  23.          MOV   AX,[>Async_Buffer_Tail]
  24.          CMP   AX,[>Async_Buffer_Head]
  25.          JNE   Rec1
  26. ;
  27. ;  Buffer still empty -- decrement elapsed time
  28. ;
  29.          POP   CX                            ;Get millesecond count
  30.          LOOP  Delay                         ;Decrement millesecond count and loop
  31. ;
  32. ;  Dropped through -- no character arrived in specified interval.
  33. ;  Return TimeOut as result.
  34. ;
  35.          MOV   BX,>TimeOut                   ;Pick up timeout value
  36.          LES   DI,[BP+<C]                    ;Get result character address
  37.     ES:  MOV   [DI],BX                       ;Store timeout value
  38.          JMP   Return                        ;Return to caller
  39. ;
  40. ;  Buffer not empty -- pick up next character.
  41. ;
  42. Rec1:    LES   DI,[>Async_Buffer_Ptr]        ;Pick up buffer address
  43.          ADD   DI,AX                         ;Add character offset
  44.      ES: MOV   BL,[DI]                       ;Get character from buffer
  45. ;
  46.          XOR   BH,BH                         ;Clear high-order bits
  47.          LES   DI,[BP+<C]                    ;Get result address
  48.      ES: MOV   [DI],BX                       ;Store character from buffer
  49. ;
  50.          INC   AX                            ;Increment tail pointer
  51.          CMP   AX,[>Async_Buffer_Size]       ;Past end of buffer?
  52.          JLE   Rec2                          ;No -- skip wrapping
  53.          XOR   AX,AX                         ;Yes -- point to start of buffer
  54. Rec2:    MOV   [>Async_Buffer_Tail],AX       ;Update tail pointer
  55.          DEC   Word [>Async_Buffer_Used]     ;Update buffer usage count
  56. ;
  57. ; If XOFF previously sent because buffer was too full, and
  58. ; now buffer is reasonably empty, send XON to get things rolling again.
  59. ;
  60.          TEST  BYTE [<Async_XOff_Sent],1    ;Check if Xoff sent
  61.          JZ    Return                       ;No -- skip.
  62. ;
  63.          MOV   AX,[>Async_Buffer_Used]      ;Pick up amount of buffer used
  64.          CMP   AX,[>Async_Buffer_Low]       ;Check if low enough
  65.          JG    Return                       ;Still too full, skip
  66. ;
  67.          MOV   AX,>XON                      ;Push XON onto stack
  68.          PUSH  AX
  69.          LEA   BX,[>Async_Send]             ;Call output routine
  70. ;
  71. ;-----WARNING---- Following statement must be fixed by hand in .OBJ file!
  72. ;---------------- Generated code should read:
  73. ;                 $FF/ $D3/
  74. ;
  75.          CALL  [BX]                         ;THIS MUST BE FIXED BY HAND!!!!!
  76. ;
  77.          MOV   BYTE [>Async_XOff_Sent],0    ;Clear Xoff flag
  78. ;
  79. Return:  AND   Byte [>Async_Line_Status],$FD ;Remove overflow flag
  80.  
  81.